<template>
  <div class="center">
    <!-- 头部 -->
    <div class="table_header flex flex_bet flex-wrap">
      <div class="table_button">
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="Refresh"></el-button>
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="formVisible = true">添加</el-button>
      </div>
      <div class="table_searchs flex felx_align">
        <div class="table_search flex">
          <el-input placeholder="搜索" v-model="searchTable" class="input-with-select" size="small">
            <el-select v-model="select" slot="prepend" placeholder="请选择" class="table_select" style="width:105px">
              <el-option label="类型" value="1"></el-option>
              <el-option label="名称" value="2"></el-option>
            </el-select>
            <el-button slot="append" icon="el-icon-search" @click="idnameSearch"></el-button>
          </el-input>
        </div>
        <dynamicTable :checkboxVal="checkboxVal" @alter="alterCheckbok"/>
      </div>
    </div>
    <el-table stripe style="width: 100%"  border fit highlight-current-row ref="tableDataRef" :data="tableData" :key="key">
      <el-table-column v-if="colData[0].istrue" min-width="50" align="center" prop="id" label="ID"></el-table-column>
      <el-table-column v-if="colData[1].istrue" min-width="50" align="center" prop="admin_name" label="创建者"></el-table-column>
      <el-table-column v-if="colData[2].istrue"  min-width="100" align="center" prop="batch" label="分发批次">
        <template slot-scope="scope">
          <p v-for="(item,index) in scope.row.batch" :key="item.id" style="margin: 0;padding: 0">{{item.batch}}</p>
        </template>
      </el-table-column>
      <el-table-column v-if="colData[3].istrue" min-width="50" align="center" prop="type" label="类型">
        <template slot-scope="scope">
          <p v-show="scope.row.type==1">自主出题</p>
          <p v-show="scope.row.type==2">上传作业任务图片</p>
        </template>
      </el-table-column>
      <el-table-column v-if="colData[4].istrue" min-width="50" align="center" prop="name" label="名称"></el-table-column>
      <el-table-column v-if="colData[5].istrue" min-width="60" align="center" prop="limit_minute" label="限时时间">
        <template slot-scope="scope">{{scope.row.limit_minute}}分钟</template>
      </el-table-column>
      <el-table-column v-if="colData[6].istrue" min-width="140" align="center" prop="deadline_time" label="提交截至时间">
        <template slot-scope="scope">{{scope.row.deadline_time| newDate}}</template>
      </el-table-column>
      <el-table-column v-if="colData[7].istrue" min-width="140" align="center" prop="create_time" label="创建日期">
        <template slot-scope="scope">{{scope.row.create_time| newDate}}</template>
      </el-table-column>
      <el-table-column v-if="colData[8].istrue" min-width="70" align="center" prop="avgGrade" label="当前平均分">
      </el-table-column>
      <el-table-column v-if="colData[9].istrue" min-width="70" align="center" prop="allSnNum"  label="应提交人数">
        <template slot-scope="scope">
          <p style="color: #0079ff" @click="openAllSn(scope.row.id)">{{scope.row.allSnNum}}</p>
        </template>
      </el-table-column>
      <el-table-column v-if="colData[10].istrue" min-width="70" align="center" prop="submit_sn_num"  label="已提交人数">
        <template slot-scope="scope">
          <p style="color: #0079ff" @click="openReadSn(scope.row.id)">{{scope.row.submit_sn_num}}</p>
        </template>
      </el-table-column>
      <el-table-column v-if="colData[11].istrue" min-width="70" align="center" prop="noReadSn"  label="待提交人数">
        <template slot-scope="scope">
          <p style="color: #0079ff" @click="openNoReadSn(scope.row.id)">{{scope.row.noReadSn}}</p>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="200" align="center">
        <template slot-scope="scope">
          <el-row>
            <el-button size="mini" type="primary" @click="toPaperConfig(scope.row.id)">配置作业</el-button>
            <el-button size="mini" type="primary" @click="openEdit(scope.row)">编辑</el-button>
            <el-button size="mini" @click="delHomeWork(scope.row.id)">删除</el-button>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="paging">
      <el-pagination :current-page.sync="listQuery.startSize" background @size-change="handleSizeChange"
                     @current-change="handleCurrentChange" :page-sizes="[10, 50, 100, 200]"
                     layout="total, sizes, prev, pager, next, jumper" :total="total" :page-size="listQuery.pageSize">
      </el-pagination>
    </div>

    <el-dialog title="应提交人数" :visible.sync="allReadSnVisible">
      <el-table :data="allReadSnData" stripe border>
        <el-table-column property="value" align="center" label="SN" min-width="150"></el-table-column>
        <el-table-column property="batch" align="center" label="批次" ></el-table-column>
        <el-table-column property="classlevel" align="center" label="班级"></el-table-column>
        <el-table-column property="sno" align="center" label="学号" ></el-table-column>
        <el-table-column property="realname" align="center" label="姓名" ></el-table-column>
        <el-table-column property="phone" align="center" label="监护人1"></el-table-column>
        <el-table-column property="phone_two" align="center" label="监护人2"></el-table-column>
      </el-table>
      <div class="paging">
        <el-pagination :current-page.sync="allReadQuery.startSize" background @size-change="allReadSizeChange"
                       @current-change="allReadCurrentChange" :page-sizes="[10, 50, 100, 200]"
                       layout="total, sizes, prev, pager, next, jumper" :total="allReadTotal" :page-size="allReadQuery.pageSize">
        </el-pagination>
      </div>
    </el-dialog>

    <el-dialog title="已提交人数" :visible.sync="readSnVisible" width="70%">
      <el-table :data="readSnData" border stripe>
        <el-table-column property="id" align="center" label="序号" min-width="50"></el-table-column>
        <el-table-column property="sn" align="center" label="SN" min-width="150"></el-table-column>
        <el-table-column property="batch" align="center" label="批次" ></el-table-column>
        <el-table-column property="classlevel" align="center" label="班级"></el-table-column>
        <el-table-column property="sno" align="center" label="学号" ></el-table-column>
        <el-table-column property="realname" align="center" label="姓名" ></el-table-column>
        <el-table-column property="phone" align="center" label="监护人1"></el-table-column>
        <el-table-column property="grade" align="center" label="分数"></el-table-column>
        <el-table-column property="create_time" align="center" label="提交时间" min-width="150">
          <template slot-scope="scope">{{scope.row.create_time| newDate}}</template>
        </el-table-column>
        <el-table-column label="操作" min-width="150" align="center">
          <template slot-scope="scope">
            <el-row>
              <el-button v-if="scope.row.is_confirm==-1" size="mini" type="primary" @click="toConfirmDialog(scope.row.id, scope.row.homeworkType)">待批改</el-button>
              <el-button v-else size="mini" type="info" disabled >已批改</el-button>
              <el-button size="mini" @click="viewHomework(scope.row.id)">查看</el-button>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
      <div class="paging">
        <el-pagination :current-page.sync="hasReadQuery.startSize" background @size-change="hasReadSizeChange"
                       @current-change="hasReadCurrentChange" :page-sizes="[10, 50, 100, 200]"
                       layout="total, sizes, prev, pager, next, jumper" :total="hasReadTotal" :page-size="hasReadQuery.pageSize">
        </el-pagination>
      </div>
    </el-dialog>

    <el-dialog title="待提交人数" :visible.sync="noReadSnVisible">
      <el-table :data="noReadSnData" border stripe>
        <el-table-column property="value" align="center" label="SN" min-width="150"></el-table-column>
        <el-table-column property="batch" align="center" label="批次" ></el-table-column>
        <el-table-column property="classlevel" align="center" label="班级"></el-table-column>
        <el-table-column property="sno" align="center" label="学号" ></el-table-column>
        <el-table-column property="realname" align="center" label="姓名" ></el-table-column>
        <el-table-column property="phone" align="center" label="监护人1"></el-table-column>
        <el-table-column property="phone_two" align="center" label="监护人2"></el-table-column>
      </el-table>
      <div class="paging">
        <el-pagination :current-page.sync="noReadQuery.startSize" background @size-change="noReadSizeChange"
                       @current-change="noReadCurrentChange" :page-sizes="[10, 50, 100, 200]"
                       layout="total, sizes, prev, pager, next, jumper" :total="noReadTotal" :page-size="noReadQuery.pageSize">
        </el-pagination>
      </div>
    </el-dialog>

    <!-- 添加弹窗 -->
    <el-dialog :title="editSubjects== true ? '编辑作业/任务': '添加作业/任务' " :visible.sync="formVisible" :close-on-click-modal="false" :close-on-press-escape="false" width="40%" @close="addFormclose">
      <el-form :model="addForm"  ref="ruleForm" :rules="rules" class="diolog_adapt" style="width: 600px" >
        <el-form-item label="批次:" label-width="130px" prop="batch">
          <el-select v-model="addForm.batch"  multiple filterable placeholder="请选择批次" clearable>
            <el-option
              v-for="item in batchArr"
              :key="item.id"
              :label="item.batch"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作业/任务类型:" label-width="130px" prop="type">
          <el-select v-model="addForm.type" placeholder="请选择">
           <el-option label="自主出题" :value="1"></el-option>
            <el-option label="上传作业任务图片" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="限时时间:" label-width="130px" prop="limit_minute">
          <el-input v-model="addForm.limit_minute" type="number" placeholder="请输入分钟数,0表示不限时" min="0" clearable></el-input>
        </el-form-item>
        <el-form-item label="预计完成时间:" label-width="130px" prop="expect_minute">
          <el-input v-model="addForm.expect_minute" type="number" placeholder="请输入预计完成所需分钟数" min="0" clearable></el-input>
        </el-form-item>
        <el-form-item label="作业/任务名称:" label-width="130px" prop="name">
          <el-input v-model="addForm.name" placeholder="请输入名称" maxlength="60" clearable></el-input>
        </el-form-item>
        <el-form-item label="作业/任务描述:" label-width="130px">
          <el-input v-model="addForm.explain" type="textarea" placeholder="请输入描述" clearable></el-input>
        </el-form-item>
        <el-form-item label="提交截至时间:" label-width="130px" prop="deadline_time">
          <el-date-picker
            v-model="addForm.deadline_time"
            type="datetime"
            placeholder="选择日期时间"
            align="center"
            value-format="timestamp"
            :default-time="'23:59:59'"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="上传附件:" label-width="130px" v-show="addForm.type===2">
          <el-upload
            class="upload-demo"
            action="#"
            :on-preview="handlePreview"
            :on-remove="imageHandleRemove"
            :file-list="addForm.imageList"
            :on-change="homeworkImgUpload"
            :auto-upload="false"
            list-type="picture">
            <el-button size="small" type="primary">点击上传</el-button>
<!--            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>-->
          </el-upload>
        </el-form-item>
        <el-form-item label="作业提交方式:" label-width="130px" v-show="addForm.type===2">
          <el-select v-model="addForm.submit_type" placeholder="请选择">
            <el-option label="文字" :value="1"></el-option>
            <el-option label="文字+附件" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="答案解析:" label-width="130px" v-show="addForm.type===2">
          <el-input type="textarea" v-model="addForm.answer_text"></el-input>
        </el-form-item>
        <el-form-item label="上传答案解析附件:" label-width="130px" v-show="addForm.type===2">
            <el-upload
              class="upload-demo"
              action="#"
              :auto-upload="false"
              :limit="1"
              :file-list="addForm.fileList"
              :on-change="contentUpload"
              :on-remove="handleRemove"
              :on-exceed="handleExceed">
              <el-button size="small" type="primary"><span>文件上传</span></el-button>
            </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="formVisible = false" size="mini" round>取 消</el-button>
        <el-button v-if="editSubjects" type="primary" size="mini" round @click="editHomework('ruleForm')">确 定
        </el-button>
        <el-button v-else type="primary" @click="addHomework('ruleForm')" size="mini" round>确定</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="isView ? '作业与任务查看' :'作业与任务批改'" class="dialogClass" :visible.sync="dialogVisible" width="50%" :fullscreen="true">
      <div v-if="homeworkType==1">
      <div class="dialogClass homeworkInfo">
        <p>作业任务类型:{{studentHomework.type}}</p>
        <p>限时时间:{{studentHomework.limit_minute}}分钟</p>
        <p>预计完成时间:{{studentHomework.expect_minute}}分钟</p>
        <p>作业任务名称:{{studentHomework.name}}</p>
        <p>作业任务描述:{{studentHomework.explain}}</p>
        <p>作业提交截至时间:{{studentHomework.deadline_time}}</p>
      </div>
      <p style="font-weight: bold;">单选题(共{{singleChoice.length}}题, 共{{singleScore}}分)</p>
      <div v-for="(item, index) in singleChoice">
        <p class="questionNameClass">{{index+1}}.{{item.question_name}}</p>
        <p>A: {{item.choices.A}}</p>
        <p>B: {{item.choices.B}}</p>
        <p>C: {{item.choices.C}}</p>
        <p>D: {{item.choices.D}}</p>
        <p>学生答案:{{item.studentAnswer}}
          <i v-if="item.isRight" class="el-icon-circle-check" style="color: #67C23A"></i>
          <i v-else class="el-icon-circle-close" style="color: #F56C6C"></i></p>
        <p>正确答案:{{item.answer}}</p>
        <p>答案解析:{{item.answer_explain}}</p>
      </div>
      <el-divider></el-divider>
      <p style="font-weight: bold;">多选题(共{{multipleChoice.length}}题, 共{{multipleScore}}分)</p>
      <div v-for="(item, index) in multipleChoice">
        <p class="questionNameClass">{{index+1}}.{{item.question_name}}</p>
        <p>A: {{item.choices.A}}</p>
        <p>B: {{item.choices.B}}</p>
        <p>C: {{item.choices.C}}</p>
        <p>D: {{item.choices.D}}</p>
        <p>学生答案:{{item.studentAnswer}}
          <i v-if="item.isRight" class="el-icon-circle-check" style="color: #67C23A"></i>
          <i v-else class="el-icon-circle-close" style="color: #F56C6C"></i></p>
        <p>正确答案:{{item.answer}}</p>
        <p>答案解析:{{item.answer_explain}}</p>
      </div>
      <el-divider></el-divider>
      <p style="font-weight: bold;">不定项选择题目(共{{indefiniteChoice.length}}题, 共{{indefiniteScore}}分)</p>
      <div v-for="(item, index) in indefiniteChoice">
        <p class="questionNameClass">{{index+1}}.{{item.question_name}}</p>
        <p>A: {{item.choices.A}}</p>
        <p>B: {{item.choices.B}}</p>
        <p>C: {{item.choices.C}}</p>
        <p>D: {{item.choices.D}}</p>
        <p>学生答案:{{item.studentAnswer}}
          <i v-if="item.isRight" class="el-icon-circle-check" style="color: #67C23A"></i>
          <i v-else class="el-icon-circle-close" style="color: #F56C6C"></i></p>
        <p>正确答案:{{item.answer}}</p>
        <p>答案解析:{{item.answer_explain}}</p>
      </div>
      <el-divider></el-divider>
      <p style="font-weight: bold;">判断题(共{{judge.length}}题, 共{{judgeScore}}分)</p>
      <div v-for="(item, index) in judge">
        <p class="questionNameClass">{{index+1}}.{{item.question_name}}</p>
        <p>学生答案:{{item.studentAnswer}}
          <i v-if="item.isRight" class="el-icon-circle-check" style="color: #67C23A"></i>
          <i v-else class="el-icon-circle-close" style="color: #F56C6C"></i></p>
        <p>正确答案:{{item.answer}}</p>
        <p>答案解析:{{item.answer_explain}}</p>
      </div>
      <el-divider></el-divider>
      <p style="font-weight: bold;">填空题(共{{fill.length}}题, 共{{fillScore}}分)</p>
      <div v-for="(item, index) in fill">
        <p class="questionNameClass">{{index+1}}.{{item.question_name}}</p>
        <p>学生答案:{{item.studentAnswer}}
          <i v-if="item.isRight" class="el-icon-circle-check" style="color: #67C23A"></i>
          <i v-else class="el-icon-circle-close" style="color: #F56C6C"></i></p>
        <p>正确答案:{{item.answer}}</p>
        <p>答案解析:{{item.answer_explain}}</p>
        <el-input size="mini" placeholder="请输入分数" v-model="item.grade" class="judgeClass" :disabled="isView">
          <el-select v-model="item.teacherJudge" slot="append" placeholder="请选择" :disabled="isView">
            <el-option label="正确" :value="1"></el-option>
            <el-option label="错误" :value="2"></el-option>
            <el-option label="半对" :value="3"></el-option>
          </el-select>
          <el-button slot="prepend" icon="el-icon-check">请批改</el-button>
        </el-input>
      </div>
      <el-divider></el-divider>
      <p style="font-weight: bold;">简答题(共{{shortAnswer.length}}题, 共{{shortAnswerScore}}分)</p>
      <div v-for="(item, index) in shortAnswer">
        <p class="questionNameClass">{{index+1}}.{{item.question_name}}</p>
        <p>学生答案:{{item.studentAnswer}}
          <i v-if="item.isRight" class="el-icon-circle-check" style="color: #67C23A"></i>
          <i v-else class="el-icon-circle-close" style="color: #F56C6C"></i></p>
        <p>正确答案:{{item.answer}}</p>
        <p>答案解析:{{item.answer_explain}}</p>
        <el-input size="mini" placeholder="请输入分数" v-model="item.grade" class="judgeClass" :disabled="isView">
          <el-select v-model="item.teacherJudge" slot="append" placeholder="请选择" :disabled="isView">
            <el-option label="正确" :value="1"></el-option>
            <el-option label="错误" :value="2"></el-option>
            <el-option label="半对" :value="3"></el-option>
          </el-select>
          <el-button slot="prepend" icon="el-icon-check">请批改</el-button>
        </el-input>
      </div>
      <span slot="footer" class="el-dialog__footer" v-show="!isView">
       <el-button type="primary" @click="confirmHomework">批改确认</el-button>
       <el-button @click="dialogVisible = false">驳回重写</el-button>
      </span>
      </div>
      <div v-else>
        <el-form :model="studentHomework" ref="studentHomework" :rules="judgeRule"   style="width: 600px">
          <el-form-item label="作业/任务类型:" label-width="130px" prop="type">
            <el-select v-model="studentHomework.type" placeholder="请选择" disabled>
              <el-option label="自主出题" :value="1"></el-option>
              <el-option label="上传作业任务图片" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="限时时间:" label-width="130px" prop="limit_minute">
            <el-input v-model="studentHomework.limit_minute" type="number" placeholder="请输入分钟数,0表示不限时" min="0" disabled></el-input>
          </el-form-item>
          <el-form-item label="预计完成时间:" label-width="130px" prop="expect_minute">
            <el-input v-model="studentHomework.expect_minute" type="number" placeholder="请输入预计完成所需分钟数" min="0" disabled></el-input>
          </el-form-item>
          <el-form-item label="作业/任务名称:" label-width="130px" prop="name">
            <el-input v-model="studentHomework.name" placeholder="请输入名称" disabled></el-input>
          </el-form-item>
          <el-form-item label="作业/任务描述:" label-width="130px">
            <el-input v-model="studentHomework.explain" type="textarea"  disabled></el-input>
          </el-form-item>
          <el-form-item label="作业提交方式:" label-width="130px" >
            <el-select v-model="studentHomework.submit_type" placeholder="请选择" disabled>
              <el-option label="文字" :value="1"></el-option>
              <el-option label="文字+附件" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="学生答题附件:" label-width="130px">
            <div  v-for="(item,index) in submitHomework.answer_file" :key="index" >
              <el-row>
              <el-image style="width: 100px; height: 100px" :src="item.url" :preview-src-list="[item.url]">
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"></i>
                </div>
              </el-image>
              </el-row>
              <el-link target="_blank" :href="item.url" :underline="false">
              <el-button size="mini" >点击下载</el-button>
              </el-link>
            </div>
          </el-form-item>
          <el-form-item label="批改得分:" label-width="130px">
            <el-input v-model="submitHomework.grade" placeholder="请输入批改得分" type="number" min="0"></el-input>
          </el-form-item>
          <el-form-item label="批改描述:" label-width="130px">
            <el-input v-model="submitHomework.judge" type="textarea" placeholder="请输入批改描述"  clearable></el-input>
          </el-form-item>
          <el-form-item label="上传批改附件:" label-width="130px">
            <el-upload
              class="upload-demo"
              action="#"
              :auto-upload="false"
              :file-list="submitHomework.judge_file"
              :on-change="judgeFileUpload"
              :on-remove="judgeFileRemove"
              >
              <el-button size="small" type="primary"><span>文件上传</span></el-button>
            </el-upload>
          </el-form-item>
          <el-form-item label-width="230px">
            <el-button type="primary" @click="confirmFileHomework('studentHomework')">批改确认</el-button>
            <el-button>驳回重写</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <delete-Dialog title="" :visible.sync="deleteDialogs.show" width="25%" top="40vh" @deleteEvents="deleteEvents" :deleteText="deleteDialogs.deleteText" />
  </div>

</template>

<script>
  import objectable from "@/utils/objectable.js";
  import dynamicTable from "@/components/DynamicTable";
  import deleteDialog from "@/components/deleteDialog";
  import tableMini from '@/utils/tableMini.js'
  import {
    getChildAdmin,
    confirmHomework,
    addHomework,
    queryHomework,
    editHomework,
    delHomework,
    getSubmitSn,
    getStudentHomework,
    getShouldSn,
    getNoSubmitSn, confirmFileHomework
  } from "@/api/launcherMade";
  import {ossFile, ossImage} from "@/utils/ossUpload";
  import {getBatchTwo} from "@/api/equipment";

  export default {
    mixins: [tableMini],
    components: {dynamicTable, deleteDialog},
    data() {
      return {
        key: 1,
        colData: [], //动态控制table
        checkboxVal: ["ID", "创建者", "批次", "类型", "名称", "限时时间", "提交截至时间", "创建日期", "当前平均分", "应提交人数", "已提交人数", "待提交人数"],
        searchTable: "",
        select: "", //搜索条件
        tableData: [],
        listQuery: {
          startSize: 1,
          pageSize: 10,
          userId: localStorage.getItem("ID"),
        },
        hasReadQuery: {
          startSize: 1,
          pageSize: 10,
          id: undefined
        },
        noReadQuery: {
          startSize: 1,
          pageSize: 10,
          id: undefined
        },
        allReadQuery: {
          startSize: 1,
          pageSize: 10,
          id: undefined
        },
        addForm: {
          batch: [],  //批次
          type: '',
          limit_minute: '',  //限时时间 单位为分钟
          expect_minute: '',  //预计完成时间  单位为分钟
          name: '',  //名称
          explain: '',  //描述
          deadline_time: '',  //提交截至时间
          imageList: [],
          fileList: [],
          submit_type: 2, //作业提交方式 1:文字 2:文字+附件
          answer_text: '',  //答案解析
        },
        formVisible: false,
        rules: {
          type: [{ required: true, message: '请选择作业/任务类型', trigger: 'change' }],
          batch: [{ required: true, message: '请选择批次', trigger: 'change' }],
          limit_minute: [{required: true, message: '请输入限时时间', trigger: 'blur'}],
          expect_minute: [{required: true, message: '请输入预计完成时间', trigger: 'blur'}],
          deadline_time: [{ required: true, message: '请选择提交截至时间', trigger: 'blur' }],
          name: [{ required: true, message: '请输入作业/任务名称', trigger: 'blur' }],
        },
        editSubjects: false,
        deleteDialogs: { show: false, deleteText: '', deleteId: 0 },
        batchArr: [],
        childrenOption: [],  //子账号可选框
        noticeTypeOptions: [{label:'作业', value:1}, {label: '通知', value: 2}, {label: '打卡任务', value: 3}],
        feedBackOptions: [{label:'文字', value:1}, {label: '文字+附件', value: 2}],
        isVisible:false,
        fileList: [],
        readSnVisible: false,
        noReadSnVisible: false,
        allReadSnVisible:false,
        readSnData: [],
        noReadSnData: [],
        allReadSnData: [],
        hasReadTotal: 0,
        noReadTotal: 0,
        allReadTotal: 0,
        dialogVisible: false,
        isView: false,
        //批改学生作业所用参数
        studentHomework: {}, //作业配置
        singleChoice: [],  //单选提
        multipleChoice: [], //多选提
        indefiniteChoice: [],  //不定项选择提
        judge: [],  //判断题
        fill: [], //填空题目
        shortAnswer: [],  //简答题
        snSubmitId: 0,
        singleScore:0,
        multipleScore:0,
        indefiniteScore:0,
        judgeScore:0,
        fillScore:0,
        shortAnswerScore:0,
        homeworkType: 1,  //1.自主出题 2.图片
        submitHomework: {
          id: 0,
          grade: 0,
          judge: '',
          answer_file:[],
          judge_file: [],
        },
        judgeRule: {
          grade: [{ required: true, message: '请选择作业/任务类型', trigger: 'blur' }],
          judge: [{ required: true, message: '请选择批次', trigger: 'blur' }],
        },

      }
    },
    created() {
      this.colData = objectable(this.checkboxVal, this.checkboxVal); //转为数组对象，好控制table
      this.getSelfHomeworkTableData()
      this.getBatchTwo()
      this.getChildAdmin()
    },
    methods: {
      Refresh() {
        this.listQuery = { startSize: 1, pageSize: 10, userId: localStorage.getItem("ID"), name: undefined, notice_type: undefined, create_time: undefined}
        this.getSelfHomeworkTableData()
      },

      openReadSn(id) {
        this.readSnVisible=true
        this.hasReadQuery.id = id
        this.getSnReadHomeworkData()
      },
      getSnReadHomeworkData() {
        getSubmitSn(this.hasReadQuery).then(res => {
          this.readSnData = res.data
          this.hasReadTotal = res.total
        }).catch(err => {
          this.readSnData = []
          this.hasReadTotal = 0
        })
      },
      openNoReadSn(id) {
        this.noReadSnVisible=true
        this.noReadQuery.id = id
        this.getNoReadHomeworkData()
      },
      getNoReadHomeworkData() {
        getNoSubmitSn(this.noReadQuery).then(res => {
          this.noReadSnData = res.data
          this.noReadTotal = res.total
        }).catch(err => {
          this.noReadSnData = []
          this.noReadTotal = 0
        })
      },
      openAllSn(id) {
        this.allReadSnVisible=true
        this.allReadQuery.id=id
        this.getAllReadHomeworkData()
      },
      getAllReadHomeworkData() {
        getShouldSn(this.allReadQuery).then(res => {
          this.allReadSnData = res.data
          this.allReadTotal = res.total
        }).catch(err => {
          this.allReadSnData = []
          this.allReadTotal = 0
        })
      },
      toConfirmDialog(id, homeworkType) {
        this.dialogVisible = true
        this.isView = false
        this.snSubmitId = id
        this.homeworkType = homeworkType
        getStudentHomework({id: id}).then(res => {
          this.studentHomework = res.data.homework
          if (homeworkType == 1) {
            this.singleChoice = res.data.singleChoice
            this.multipleChoice = res.data.multipleChoice
            this.indefiniteChoice = res.data.indefiniteChoice
            this.judge = res.data.judge
            this.fill = res.data.fill
            this.shortAnswer = res.data.shortAnswer
            this.singleScore = res.data.singleScore
            this.multipleScore = res.data.multipleScore
            this.indefiniteScore = res.data.indefiniteScore
            this.judgeScore = res.data.judgeScore
            this.fillScore = res.data.fillScore
            this.shortAnswerScore = res.data.shortAnswerScore
          }else {
            this.submitHomework = res.data.submitHomework
          }
        }).catch(err => {
        })
      },
      confirmHomework() {
        let allQuestion = [];
        this.singleChoice.forEach((value, index) => {
          allQuestion.push(value)
        })
        this.multipleChoice.forEach((value, index) => {
          allQuestion.push(value)
        })
        this.indefiniteChoice.forEach((value, index) => {
          allQuestion.push(value)
        })
        this.judge.forEach((value, index) => {
          allQuestion.push(value)
        })
        this.fill.forEach((value, index) => {
          allQuestion.push(value)
        })
        this.shortAnswer.forEach((value, index) => {
          allQuestion.push(value)
        })
        let param = {
          userId: localStorage.getItem('ID'),
          id: this.snSubmitId,
          allQuestion: JSON.stringify(allQuestion),
        }
        confirmHomework(param).then(res => {
          this.$message.success(res.msg)
          this.getSnReadHomeworkData()
        }).catch(err => {
        })
      },
      confirmFileHomework(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let form = JSON.parse(JSON.stringify(this.submitHomework))
            form.userId = localStorage.getItem('ID')
            confirmFileHomework(form).then(res => {
              this.$message.success(res.msg)
              this.dialogVisible = false
            }).catch(err => {})
          } else {
            return false;
          }
        });
      },
      viewHomework(id) {
        this.dialogVisible = true
        this.isView = true
        getStudentHomework({id: id}).then(res => {
          this.studentHomework = res.data.homework
          this.singleChoice = res.data.singleChoice
          this.multipleChoice = res.data.multipleChoice
          this.indefiniteChoice = res.data.indefiniteChoice
          this.judge = res.data.judge
          this.fill = res.data.fill
          this.shortAnswer = res.data.shortAnswer
        }).catch(err => {
        })
      },
      toPaperConfig(id) {
        this.$router.push({name:'contentManage/paperConfig', query:{id: id}});
      },
      //搜索,1:课程名称
      idnameSearch() {
        if (!this.select) return this.$message.warning("请先选择查询条件");
        this.listQuery.startSize = 1
        this.listQuery.pageSize = 10
        switch (this.select) {
          case '1':
            this.listQuery.type = this.searchTable
            this.getSelfHomeworkTableData();
            break;
          case '2':
            this.listQuery.name = this.searchTable
            this.getSelfHomeworkTableData();
            break;
          case '3':
            this.listQuery.create_time = this.searchTable
            this.getSelfHomeworkTableData();
            break;
        }
      },
      getBatchTwo() {
        getBatchTwo({ userId: localStorage.getItem("ID") }).then(res => {
          this.batchArr = res.data
        }).catch(err => {
          this.batchArr = []
        })
      },
      getChildAdmin() {
        getChildAdmin({ userId: localStorage.getItem("ID") }).then(res => {
          this.childrenOption = res.data
        }).catch(err => {
          this.childrenOption = []
        })
      },
      openEdit(row) {
        this.formVisible = true
        this.editSubjects=true
        this.isVisible = row.notice_type === 3
        this.addForm = {
          id: row.id,
          batch: row.batchArr,  //批次
          type: row.type,
          limit_minute: row.limit_minute,  //限时时间 单位为分钟
          expect_minute: row.expect_minute,  //预计完成时间  单位为分钟
          name: row.name,  //名称
          explain: row.explain,  //描述
          deadline_time: row.deadline_time * 1000,  //提交截至时间
          imageList: row.imageList,
          fileList: row.fileList,
          submit_type: row.submit_type, //作业提交方式 1:文字 2:文字+附件
          answer_text: row.answer_text,  //答案解析
        }
      },
      addHomework(formName) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            let addForm = JSON.parse(JSON.stringify(this.addForm))
            addForm.last_ip = sessionStorage.getItem("Ip")
            addForm.userId = localStorage.getItem("ID")
            addHomework(addForm).then(res => {
              if(res.code==200){
                this.$message.success(res.msg)
                this.getSelfHomeworkTableData()
              }
              this.formVisible = false
            }).catch(err => {
            })
          } else {
            return false;
          }
        });
      },
      getSelfHomeworkTableData() {
        queryHomework(this.listQuery).then(res => {
          if(res.code==200){
            this.tableData = res.data
            this.total = res.total
          }else{
            this.$message.error(this.res.msg)
          }
        }).catch(err => {
          this.tableData = []
          this.total = 0
        })
      },
      editHomework(formName) {
        this.$refs[formName].validate(valid => {
          if (valid) {
            let editForm = JSON.parse(JSON.stringify(this.addForm))
            editForm.last_ip = sessionStorage.getItem("Ip")
            editForm.userId = localStorage.getItem("ID")
            editHomework(editForm).then(res => {
              this.$message.success(res.msg)
              this.formVisible = false
              this.getSelfHomeworkTableData()
            }).catch(err => {
            })
          } else {
            return false;
          }
        });
      },

      handlePreview(file) {
        console.log(file);
      },
      //作业图片上传
      homeworkImgUpload(file, fileList) {
        ossImage(file.raw,file.name).then(ossUrl => {//文件上传
          this.addForm.imageList.push({name:file.name, url: ossUrl})
          this.$message.success("上传成功")
        }).catch(err => {
          this.$message.error("文件上传失败")
        })
      },
      //上传图片删除
      imageHandleRemove(file, fileList) {
        this.addForm.imageList = this.addForm.imageList.filter(item => {
          return item.name != file.name
        })
      },
      judgeFileUpload(file, fileList) {
        ossFile(file.raw,file.name).then(ossUrl => {//文件上传
          this.submitHomework.judge_file.push({name:file.name, url: ossUrl})
          this.$message.success("上传成功")
        }).catch(err => {
          this.$message.error("文件上传失败")
        })
      },
      judgeFileRemove(file,fileList) {
        this.submitHomework.fileList = this.addForm.fileList.filter(item => {
          return item.name != file.name
        })
      },
      delHomeWork(id) {
        this.deleteDialogs.show = true
        this.deleteDialogs.deleteId = id
      },
      //删除按钮事件
      deleteEvents() {
        let params = {
          userId: localStorage.getItem("ID"),
          last_ip: sessionStorage.getItem("Ip"),
          id: this.deleteDialogs.deleteId,
        }
        delHomework(params).then(res => {
          if(res.code==200){
            this.$message.success(res.msg)
          }else{
            this.$message.error(res.msg)
          }
          this.getSelfHomeworkTableData()
        }).catch(err => {
          console.log("请求失败", err)
        })
      },
      //分页
      handleSizeChange(val) {
        this.listQuery.pageSize = val
        this.getSelfHomeworkTableData()
      },
      handleCurrentChange(val) {
        this.listQuery.startSize = val
        this.getSelfHomeworkTableData()
      },
      hasReadSizeChange(val) {
        this.hasReadQuery.pageSize = val
        this.getSnReadHomeworkData()
      },
      hasReadCurrentChange(val) {
        this.hasReadQuery.startSize = val
        this.getSnReadHomeworkData()
      },
      noReadSizeChange(val) {
        this.noReadQuery.pageSize = val
        this.getNoReadHomeworkData()
      },
      noReadCurrentChange(val) {
        this.noReadQuery.startSize = val
        this.getNoReadHomeworkData()
      },
      allReadSizeChange(val) {
        this.allReadQuery.pageSize = val
        this.getAllReadHomeworkData()
      },
      allReadCurrentChange(val) {
        this.allReadQuery.startSize = val
        this.getAllReadHomeworkData()
      },
      //下拉动态table子组件
      alterCheckbok(key, conte) {
        this.key = key;
        this.colData.filter(i => {
          if (conte.indexOf(i.title) != -1) {
            i.istrue = false;
            this.$nextTick(() => {
              this.$refs.tableDataRef.doLayout();
            });
          } else {
            i.istrue = true;
            this.$nextTick(() => {
              this.$refs.tableDataRef.doLayout();
            });
          }
        });
      },
      //文件上传
      contentUpload(file, fileList) {
        ossFile(file.raw,file.name).then(ossUrl => {//文件上传
          this.addForm.fileList.push({name:file.name, url: ossUrl})
          this.$message.success("上传成功")
        }).catch(err => {
          this.$message.error("文件上传失败")
        })
      },
      handleRemove(file, fileList) {
        this.addForm.fileList = this.addForm.fileList.filter(item => {
          return item.name != file.name
        })
      },
      handleExceed(files, fileList) {
        this.$message.warning('当前仅支持上传单个答案解析附件');
      },
      //编辑添加表单关闭事件
      addFormclose() {
        this.editSubjects=false
        this.$nextTick(() => {
          this.addForm = this.$options.data().addForm
        })
      },
    }
  }
</script>

<style>
  .dialogClass .el-dialog__body {
    padding: 20px;
    padding-top: 0px;
    padding-bottom: 0px;
    margin-left: 20px;
    color: #606266;
    font-size: 14px;
    max-height: 800px;
  }
  .dialogClass .el-dialog__footer {
    text-align: center;
    display: flex;
    justify-content: center;
  }
  .dialogClass .homeworkInfo {
    display: flex;
    justify-content: space-between;
    font-size: 18px;
  }
  .questionNameClass {
    font-size: 15px;
    color: black;
  }

  .judgeClass {
    width: 30%;
  }
  .judgeClass .el-input-group__prepend {
    background-color: #fff;
  }
  .judgeClass .el-select {
    width: 130px;
  }
  /*注意此样式不可以放在scope属性下面,否则样式不生效*/
</style>



